<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../libs/vue.js"></script>
</head>
<body>
    <div id="app">
        <h1 id="box">{{msg}}</h1>
        <hr>
        <button @click="updateMsg">点击修改msg</button>
        <hr>
        <button @click="del">点击销毁vue</button>
    </div>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                msg:'hello vue'
            },
            methods: {
                handle(){
                    console.log('handle 函数')
                },
                updateMsg(){
                    this.msg = '哈哈哈'
                },
                del(){
                    this.$destroy()
                }
            },
            // 创建之前, 没有函数和变量
            beforeCreate() {
                console.log('===========')
                console.log('创建之前')
                console.log(this.msg)
                console.log(this.handle)
            },
            // 已经创建，有函数和数据变量，ajax请求后台数据一般在这个生命周期
            created() {
                console.log('===========')
                console.log('已经创建')
                console.log(this.msg)
                console.log(this.handle)
            },
            // 挂载之前
            beforeMount() {
                console.log('===========')
                console.log('挂载之前')
                let box = document.getElementById('box')
                console.log(box)
            },
            // 已经挂载,需要操作dom在这个生命周期，类似于swiper轮播图
            mounted() {
                console.log('===========')
                console.log('已经挂载')
                let box = document.getElementById('box')
                console.log(box)
            },
            // 修改之前
            beforeUpdate() {
                console.log('===========')
                console.log('修改之前')
                let box = document.getElementById('box').innerHTML
                console.log(box)
            },
            // 已经修改
            updated() {
                console.log('===========')
                console.log('已经修改')
                let box = document.getElementById('box').innerHTML
                console.log(box)
            },
            // 销毁之前
            beforeDestroy() {
                console.log('===========')
                console.log('销毁之前')
            },
            // 已经销毁
            destroyed() {
                console.log('===========')
                console.log('已经销毁')
            },
        })
    </script>
</body>
</html>